package com.liao.ten.image;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.liao.ten.R;
import com.liao.ten.utils.ContentUtils;
import com.squareup.picasso.Picasso;

public class ItemImageFragment extends Fragment {

    ImageView picIv;
    TextView titleTv, painterTv, summaryTv, authorTv;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.item_image_layout, container, false);
        initView(view);
        Bundle bundle = getArguments();
        ImageBean.ResultBean bean = (ImageBean.ResultBean) bundle.getSerializable("data1");
        ImageDetailInfo imageDetailInfo = (ImageDetailInfo) bundle.getSerializable("data2");
        String imageURL = bean.getImage();
        if (!TextUtils.isEmpty(imageURL)) {
            imageURL = ContentUtils.PICTURE_DISPLAY_URL + imageURL;
            Picasso.get().load(imageURL).into(picIv);
        }
        titleTv.setText(bean.getTitle());
        summaryTv.setText(bean.getSummary());
        painterTv.setText(imageDetailInfo.getAuthorbrief());
        authorTv.setText(imageDetailInfo.getText2());
        return view;
    }

    /* 初始化控件 */
    private void initView(View view) {
        picIv = view.findViewById(R.id.itemimage_iv);
        titleTv = view.findViewById(R.id.itemimage_tv_title);
        painterTv = view.findViewById(R.id.itemimage_tv_painter);
        summaryTv = view.findViewById(R.id.itemimage_tv_summary);
        authorTv = view.findViewById(R.id.itemimage_tv_author);
    }
}